package com.springboot.start.springbootorigin.service.impl;

import com.springboot.start.springbootorigin.entity.User;
import com.springboot.start.springbootorigin.mapper.UserMapper;
import com.springboot.start.springbootorigin.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author FireWang
 * @date 2020/11/08
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public String sayhello() {
        String what2see = "Hello, SpringBoot!(from core)";
        List<Map> saysomething = userMapper.selectBySql("select * from test_user");
        if (saysomething.size() > 0) {
            what2see = saysomething.toString();
        }
        return what2see;
    }

    @Override
    public String addUser(User user) {
        String what2see = "";
        int cunms = userMapper.insert(user);
        if (cunms > 0) {
            what2see = "user " + user.getUserName() + " is add!";
        }
        return what2see;
    }

    @Override
    public String deleteUser(int id) {
        String what2see = "";
        int cunms = userMapper.deleteById(id);
        if (cunms > 0) {
            what2see = "user is delete!";
        }
        return what2see;
    }
}
